package com.cipta.lomob.adapter;

import java.util.LinkedList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cipta.lomob.R;
import com.cipta.lomob.model.Comments;

public class CommentsAdapter extends BaseAdapter{
	Activity activity;
	LayoutInflater inflater;
	LinkedList<Comments> listItem;
	
	public CommentsAdapter(Activity activity, LinkedList<Comments> listItem) {
		// TODO Auto-generated constructor stub
		this.activity = activity;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.listItem = listItem;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listItem.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View view = arg1;
		ViewHolder holder = null;
		
		if (view == null) {
			holder = new ViewHolder();
			view = inflater.inflate(R.layout.inf_item_comments, null);
			holder.txtComment = (TextView)view.findViewById(R.id.inf_txt_item_comments);
			holder.txtTime = (TextView)view.findViewById(R.id.inf_txt_item_comments_time);
			holder.imgAvatar = (ImageView)view.findViewById(R.id.inf_img_item_comments_avatar);
			view.setTag(holder);
		} else {
			holder = (ViewHolder)view.getTag();
		}
		
		holder.txtComment.setText(listItem.get(arg0).getComment());
		holder.txtTime.setText(listItem.get(arg0).getTime());
		holder.imgAvatar.setImageResource(listItem.get(arg0).getAvatar());
		
		return view;
	}
	
	static class ViewHolder{
		TextView txtComment, txtTime;
		ImageView imgAvatar;
	}

}